import React from 'react';
import {Link} from "react-router-dom";
import GUtils from "@/utils";
import {Tag} from "antd";
import moment from "moment";

const Config = (Action) => {
    const Handlers = {
        enabled({id,enabled,name}) {
            enabled=!enabled;
            let op = enabled ? "启用" :"禁用";
            GUtils.confirm(op,`确认${op}门店 [${name}] 吗?`,()=>{
                Action.enabled(id, enabled);
            });
        }
    }
    const columns = [
        //  render(v, vo) { return  <Link to={`detail/view?id=${vo.id}`} className="mr-8">{v}</Link>;}};
        {title:"UID",dataIndex:"uid",width:120},
        {title:"手机号",dataIndex:"phone",width:120},
        {title:"昵称",dataIndex:"username",width:120},
        {title:"可用余额",dataIndex:"balance",width:120,render(v,vo){
            let {PAGE_USER_BALANCE} = window.CONFIG;
            return <Link to={`${PAGE_USER_BALANCE}?userPhone=${vo.phone}`} className="mr-8">{v}</Link>
        }},
        {title:"状态",dataIndex:"enabled",width:80, render: GUtils.renderEnabledValue},


        {title:"会员信息",dataIndex:"vipOrderId",width:120, render(v, vo){
            let date = vo.vipExpirationEndDate;
            if(!date){
                return <div></div>
            }
            date = moment(date);
            let now = moment.now();
            return <div>
                <div className="text-center">{date.isAfter(now) ? <Tag color="success">会员</Tag> : <Tag color="error">过期</Tag>}</div>

                <div>产品：<Tag>{vo.vipProductName} ({vo.vipDays}天)</Tag></div>
                <div>免费时间：{vo.vipFreeTime}分钟</div>
                <div>有效期：{GUtils.dateFormatter(vo.vipExpirationEndDate)}</div>
            </div>
        }},

        {title: '操作',dataIndex: 'id',width: 80,render(id,vo){
                return <div>
                    {vo.enabled} {GUtils.renderEnabledLink(vo, "用户", "username", Action)}
                </div>
            }},
    ];
    return {
        ...window.CONFIG.getPagerConfig(Action), columns
    };
};


export default Config;
